package com.yykj.hospital.server.model.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.yykj.common.constant.CommonConstant;
import com.yykj.common.enums.HospitalOnlineTypeEnum;
import com.yykj.common.util.serializer.LocalDate2LongSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DoctorOnlinePriceSetting {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty("ID")
    private Integer id;

    @ApiModelProperty("医院ID")
    private Integer hospitalId;

    @ApiModelProperty("医生ID")
    private String doctorId;

    @Enumerated(value = EnumType.STRING)
    @ApiModelProperty("在线问诊类型")
    private HospitalOnlineTypeEnum type;

    @ApiModelProperty("价格")
    @Column(precision = 10, scale = 2)
    private BigDecimal price;

    @ApiModelProperty("服务时长，单位分钟")
    private Integer time;

    @CreationTimestamp
    @JsonSerialize(using = LocalDate2LongSerializer.class)
    private LocalDateTime addTime;
    @UpdateTimestamp
    @JsonSerialize(using = LocalDate2LongSerializer.class)
    private LocalDateTime modifyTime;

    public static DoctorOnlinePriceSetting defaultDoctorOnlinePriceSetting(Integer hospitalId,String doctorId, HospitalOnlineTypeEnum type) {

        DoctorOnlinePriceSetting build = DoctorOnlinePriceSetting.builder()
                .hospitalId(hospitalId)
                .doctorId(doctorId)
                .type(type)
                .build();

        switch (type) {
            case pic:
                build.setPrice(CommonConstant.PIC_PRICE);
                build.setTime(30);
                break;
            case video:
                build.setPrice(CommonConstant.VIDEO_PRICE);
                build.setTime(15);
                break;
            case voice:
                build.setPrice(CommonConstant.VOICE_PRICE);
                build.setTime(15);
                break;
        }
        return build;

    }


}
